const os = require("os");

function getWlanAddress() {
  const networkInterfaces = os.networkInterfaces();

  let wlanAddress = null;

  for (const [interfaceName, interfaces] of Object.entries(networkInterfaces)) {
    if (interfaceName === "WLAN") {
      for (const { address, family, internal } of interfaces) {
        if (family === "IPv4" && !internal) {
          wlanAddress = address;
          break;
        }
      }
      if (wlanAddress) break;
    }
  }
  return wlanAddress;
}

module.exports = getWlanAddress;
